package com.gzhryc.common;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class PatternHelper {

	private List<Pattern> excludePatternList = new ArrayList<Pattern>();
	private List<Pattern> matchedPatternList = new ArrayList<Pattern>();

	public boolean isExclude(String str) {
		for (int i = 0; i < excludePatternList.size(); i++) {
			Pattern pat = excludePatternList.get(i);
			if (pat.matcher(str).find()) {
				return true;
			}
		}
		return false;
	}

	public boolean isMatched(String str, boolean def) {
		if (matchedPatternList.size() == 0) {
			return def;
		}
		for (int i = 0; i < matchedPatternList.size(); i++) {
			Pattern pat = matchedPatternList.get(i);
			if (pat.matcher(str).find()) {
				return true;
			}
		}
		return false;
	}

	public void addExcludePattern(Pattern pat) {
		excludePatternList.add(pat);
	}
	
	public void addExcludePattern(String regex) {
		excludePatternList.add(Pattern.compile(regex));
	}

	public void addMatchedPatternList(Pattern pat) {
		matchedPatternList.add(pat);
	}
	
	public void addMatchedPatternList(String regex) {
		matchedPatternList.add(Pattern.compile(regex));
	}
}
